package com.lhkj.ct.admin.modules.patient.controller;


import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lhkj.ct.base.annntation.Log;
import com.lhkj.ct.base.enums.ActionType;
import com.lhkj.ct.base.model.dto.PageQuery;
import com.lhkj.ct.base.model.ro.ActionResult;
import com.lhkj.ct.meta.modules.patient.model.entity.TblUnitTask;
import com.lhkj.ct.meta.modules.patient.service.service.ITblUnitTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * <p>
 * 单位任务 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2023-12-23
 */
@RestController
@RequestMapping("api/system/unitTask")
@Api(tags = {"1.2单位任务"})
@Validated
public class UnitTaskController {

    @Resource
    private ITblUnitTaskService unitTaskService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "任务列表")
    @GetMapping("list")
    //@RequiresPermissions(value = {"system:patUnit:list"}, logical = Logical.OR)
    public ActionResult<IPage<TblUnitTask>> selectPatUnitTree(TblUnitTask task, PageQuery pageQuery) {
        return ActionResult.success(unitTaskService.selectTaskPage(task, pageQuery));
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "任务详情")
    @GetMapping("{taskId}/get")
    //@RequiresPermissions(value = {"system:patUnit:get", "system:patUnit:update"}, logical = Logical.OR)
    public ActionResult<TblUnitTask> all(@PathVariable String taskId) {
        return ActionResult.success(unitTaskService.getById(taskId));
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增")
    @PostMapping("insert")
    @Log(title = "单位任务", actionType = ActionType.INSERT)
    //@RequiresPermissions(value = {"system:patUnit:insert"}, logical = Logical.OR)
    public ActionResult<Void> insert(@RequestBody TblUnitTask unitTask) {
        unitTask.setStatus(0);
        return ActionResult.judge(unitTaskService.save(unitTask));
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改")
    @PutMapping("update")
    @Log(title = "单位任务", actionType = ActionType.UPDATE)
    //@RequiresPermissions(value = {"system:patUnit:update"}, logical = Logical.OR)
    public ActionResult<Void> update(@RequestBody TblUnitTask unitTask) {
        return ActionResult.judge(unitTaskService.updateById(unitTask));
    }

    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "删除任务，支持批量")
    @DeleteMapping("delete")
    @Log(title = "单位任务", actionType = ActionType.DELETE)
    //@RequiresPermissions(value = {"system:patUnit:delete"}, logical = Logical.OR)
    public ActionResult<Void> delete(@NotEmpty(message = "任务id不能为空") @RequestBody List<String> ids) {
        return ActionResult.judge(unitTaskService.removeByIds(ids));
    }

    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "处理任务，支持批量")
    @PutMapping("processed")
    @Log(title = "单位任务", actionType = ActionType.UPDATE)
    //@RequiresPermissions(value = {"system:patUnit:delete"}, logical = Logical.OR)
    public ActionResult<Void> update(@NotEmpty(message = "任务id不能为空") @RequestBody List<String> ids) {
        return ActionResult.judge( unitTaskService.update(new LambdaUpdateWrapper<TblUnitTask>().in(TblUnitTask::getId, ids).set(TblUnitTask::getStatus, 1)));
    }
}
